package com.app.util;

import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;

public class UploadUtils {


    /**
     * 验证图片的格式
     *
     * @param file 图片
     * @return
     */
    public static boolean imageTypeRight(MultipartFile file) {
        // 首先校验图片格式
        String[] imageType = {"jpg", "jpeg", "png", "bmp", "gif","xlx", "xlsx","doc","docx","ppt","pdf"};
        // 获取文件名，带后缀
        String originalFilename = file.getOriginalFilename();
        // 获取文件的后缀格式
        String fileSuffix = originalFilename.substring(originalFilename.lastIndexOf(".") + 1).toLowerCase();  //不带 .
        if (!Arrays.asList(imageType).contains(fileSuffix)) return false;
        return true;
    }


}
